package com.gs.synedocket.dialog;

import android.Manifest;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;

import com.gs.synedocket.R;
import com.gs.synedocket.util.FileUtils;
import com.gs.synedocket.util.PermissionUtil;
import com.gs.synedocket.util.PhotoUtil;

public class CommDialogUtils {
    private static ProgressDialog progressDialog;

    public static void showProgressDialog(Context context) {
        // 展示進度條
        progressDialog = new ProgressDialog(context);
        progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        progressDialog.setTitle(R.string.downloading);
        progressDialog.setMax(100);
        progressDialog.setCancelable(false);
        progressDialog.show();
    }

    public static void setProgress(int progress) {
        progressDialog.setProgress(progress);
    }

    public static void dismissProDialog() {
        progressDialog.dismiss();
    }

    public static void showComboPicDialog(final Activity activity, String title) {
        final ComboPicDialog comboPicDialog = new ComboPicDialog(activity);
        comboPicDialog.setTitle(title).setClickListener(new ComboPicDialog.OnClickListener() {
            @Override
            public void camera() {
                if (FileUtils.getInstance().hasSdCard()) {
                    if (PermissionUtil.addPermission(activity, new String[]{Manifest.permission.CAMERA}, ComboPicDialog.PIC_CAMERA)) {
                        PhotoUtil.getInstance().toCamera(activity);
                    }
                    comboPicDialog.dismiss();
                }
            }

            @Override
            public void gallery() {
                if (PermissionUtil.addPermission(activity, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, ComboPicDialog.PIC_GALLERY)) {
                    PhotoUtil.getInstance().toGallery(activity);
                }
                comboPicDialog.dismiss();
            }

            @Override
            public void cancel() {
                comboPicDialog.dismiss();
            }
        }).show();
    }

}
